package com.shiftl.guestbook.server;

import com.google.gwt.user.server.rpc.RemoteServiceServlet;
import com.shiftl.data.aroma.dao.DAOFactory;
import com.shiftl.data.aroma.dao.IncenseDAO;
import com.shiftl.data.aroma.entity.EntFactory;
import com.shiftl.data.aroma.model.Incense;
import com.shiftl.guestbook.client.GreetingService;

/**
 * The server side implementation of the RPC service.
 */
@SuppressWarnings("serial")
public class GreetingServiceImpl extends RemoteServiceServlet implements GreetingService {

	public String greetServer(final String input) {
		final String serverInfo = getServletContext().getServerInfo();
		final String userAgent = getThreadLocalRequest().getHeader("User-Agent");
		final IncenseDAO incDAO = DAOFactory.newDAO(IncenseDAO.class);
		final Incense inc = EntFactory.newIncense("testIncense", "description1");
		incDAO.saveIncense(inc);
		return "Hello, " + input + "!<br><br>I am running " + serverInfo + ".<br><br>It looks like you are using:<br>"
		       + userAgent + "incense id is" + inc.getEncodedKey();
	}
}
